home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / util / misc / randomFileName.lha / randfile / randFileName.rx < prev   
Encoding:
Text File  |  2001-05-06  |  1.8 KB  |  109 lines

  1. /*
  2. randFileName.rx -- Create a random file name for given file
  3. Written in ARexx
  4. © 2001 Carl Svensson
  5. Version 0.9
  6. */
  7.  
  8. /* Check for -- and load -- rexxsupport.library */
  9. if ~show("L","rexxsupport.library") then
  10.   call addlib('rexxsupport.library',0,-30,0)
  11.  
  12. /* set up variables */
  13. randname=""
  14. count=1
  15.  
  16. /*
  17. get command line arguments
  18.  len: string length of the random file name (excluding suffix)
  19.  file: file to replace name for
  20.  suffix: "dot"-extension (for example, in "image.gif", "gif" is the suffix)
  21. */
  22. parse arg len file suffix
  23.  
  24. /* start timer */
  25. time(r)
  26.  
  27. /* hande filename length */
  28. if len < 1 then do
  29.   say "LENGTH must be 1 or greater!"
  30.   exit
  31. end
  32. len=len+1
  33.  
  34. /* check for file */
  35. if exists(file) then
  36.   renfile=1
  37. else
  38.   renfile=0
  39.  
  40. /* handle filename suffix */
  41. suffix=strip(suffix)
  42. if ~(suffix="") then do
  43.   dotstr=substr(suffix,1,1)
  44.   if dotstr="." then
  45.     suffix=suffix
  46.   else
  47.     suffix="."suffix
  48. end
  49. else do
  50.   suffix=".rnd"
  51. end
  52.  
  53. /* set up alphabet array */
  54. alpha.1='a'
  55. alpha.2='b'
  56. alpha.3='c'
  57. alpha.4='d'
  58. alpha.5='e'
  59. alpha.6='f'
  60. alpha.7='g'
  61. alpha.8='h'
  62. alpha.9='i'
  63. alpha.10='j'
  64. alpha.11='k'
  65. alpha.12='l'
  66. alpha.13='m'
  67. alpha.14='n'
  68. alpha.15='o'
  69. alpha.16='p'
  70. alpha.17='q'
  71. alpha.18='r'
  72. alpha.19='s'
  73. alpha.20='t'
  74. alpha.21='u'
  75. alpha.22='v'
  76. alpha.23='w'
  77. alpha.24='x'
  78. alpha.25='y'
  79. alpha.26='z'
  80.  
  81. call newname
  82.  
  83. /* rename file if the file exists, otherwise print new file name */
  84. if renfile then do
  85.   rename(file,randname)
  86.   say file" renamed to "randname"!"
  87. end
  88. else do
  89.   say "New name: "randname
  90. end
  91.  
  92. exit
  93.  
  94. /* generate random name */
  95. newname: 
  96.   randname=""
  97.   do while count < len
  98.     rseed=right(time(e),2)*time(s)
  99.     rnum=random(1,26,rseed)
  100.     rchar=alpha.rnum
  101.     randname=randname""rchar
  102.     count=count+1
  103.   end
  104.   count=1
  105.   randname=randname""suffix
  106.   if renfile & exists(randname) then
  107.     call newname
  108. return
  109.